package cn.tedu.spring;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Author：程Sir
 * Name： framework
 * Content:
 */
@Controller
@RequestMapping("user")
public class UserController {

    // 请求的路径：http://localhost:8080/SpringMvcTest01/user/reg.do?username=%22%E5%BC%A0%E4%B8%89%22&password=123456&age=18
    @RequestMapping(path = "/reg.do",method = RequestMethod.GET)
    @ResponseBody
    public String handleReg(String username,String password,Integer age){
        System.out.println("username="+username);
        System.out.println("password="+password);
        System.out.println("age="+age);
        return "ok!!!!";
    }
    // 请求的路径：http://localhost:8080/SpringMvcTest01/user/register.do?username=%22%E5%BC%A0%E4%B8%89%22&password=123456&age=18
    @RequestMapping(path = "/register.do",method = RequestMethod.GET)
    @ResponseBody
    public String handleReg1(HttpServletRequest request){
        System.out.println("username="+request.getParameter("username"));
        System.out.println("password="+request.getParameter("password"));
        //得到的age是一个字符串，需要是进行转换！
        System.out.println("age="+request.getParameter("age"));
        return "ok!!!!";
    }

    // 请求的路径：http://localhost:8080/SpringMvcTest01/user/register1.do?username=%22%E5%BC%A0%E4%B8%89%22&password=123456&age=18
    @RequestMapping(path = "/register1.do",method = RequestMethod.GET)
    @ResponseBody
    public String handleReg2(User user){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
        System.out.println("age="+user.getAge());
        return "ok!!!!";
    }

    // 请求的路径：http://localhost:8080/SpringMvcTest01/user/register1.do?username=%22%E5%BC%A0%E4%B8%89%22&password=123456&age=18
    @RequestMapping(path = "/register2.do",method = RequestMethod.GET)
    @ResponseBody
    public String handleReg3(User user,Integer id){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
        System.out.println("age="+user.getAge());
        System.out.println("id="+id);
        return "ok!!!!";
    }


}
